package cn.wolfcode.p2p.controller;

import cn.wolfcode.p2p.base.exception.DisplayableException;
import cn.wolfcode.p2p.base.qo.QueryObject;
import cn.wolfcode.p2p.base.util.JSONResult;
import cn.wolfcode.p2p.business.domain.RechargeOffline;
import cn.wolfcode.p2p.business.service.IPlatformBankInfoService;
import cn.wolfcode.p2p.business.service.IRechargeOfflineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 后台的充值审核
 */
@Controller
public class RechargeOfflineController {
    @Autowired
    private IRechargeOfflineService rechargeOfflineService;
    @Autowired
    private IPlatformBankInfoService platformBankInfoService;

    @RequestMapping("/rechargeOffline")
    public String rechargeOffline(@ModelAttribute("qo") QueryObject qo, Model model){
        model.addAttribute("pageInfo", rechargeOfflineService.queryPage(qo));
        model.addAttribute("banks", platformBankInfoService.selectAll());
        return "rechargeoffline/list";
    }


    @RequestMapping("/rechargeOffline_audit")
    @ResponseBody
    public JSONResult audit(Long id, String remark, Integer state){
        JSONResult result = null;
        try {
            rechargeOfflineService.audit(id, remark, state);
            result = new JSONResult("");
        } catch (DisplayableException ex) {
            //异常需要在前台显示
            ex.printStackTrace();
            result = new JSONResult(false, ex.getMessage());
        } catch (Exception e){
            //异常记录到数据库或日志文件中
            e.printStackTrace();
            result = new JSONResult(false, "系统异常,请联系管理员");
        }
        return result;
    }
}
